//
//  welcomeViewController.swift
//  WEIBO
//
//  Created by 李龙 on 15/6/28.
//  Copyright © 2015年 itheima. All rights reserved.
//

import UIKit
import SDWebImage
class welcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        if let urlString = shareAccount?.avatar_large
        {
            iconView.sd_setImageWithURL(NSURL(string: urlString))
        }
        // Do any additional setup after loading the view.
    }

    var bottomConstraint: NSLayoutConstraint?
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        bottomConstraint?.constant = -(UIScreen.mainScreen().bounds.height-200)
        UIView.animateWithDuration(1.0, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 10.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                UIView.animateWithDuration(1.0, animations: { () -> Void in
                    self.messageLable.alpha = 1.0
                    }, completion: { (_) -> Void in
                        NSNotificationCenter.defaultCenter().postNotificationName(HMSwitchRootVCNotification, object: true)
                })
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    override func loadView() {
        view = UIView()
        let backImageView = UIImageView(image: UIImage(named: "ad_background"))
        view.addSubview(backImageView)
        view.addSubview(iconView)
        view.addSubview(messageLable)
        backImageView.translatesAutoresizingMaskIntoConstraints = false
        view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[subView]|", options: NSLayoutFormatOptions.AlignAllBaseline, metrics: nil, views: ["subView":backImageView]))
        view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[subView]|", options: NSLayoutFormatOptions.AlignAllBaseline, metrics: nil, views: ["subView":backImageView]))
        iconView.translatesAutoresizingMaskIntoConstraints = false
        view.addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 0.0))
        bottomConstraint = NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: -160)
        view.addConstraint(bottomConstraint!)
        view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[subView(90)]", options: NSLayoutFormatOptions.AlignAllBaseline, metrics: nil, views: ["subView":iconView]))
        view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[subView(90)]", options: NSLayoutFormatOptions.AlignAllBaseline, metrics: nil, views: ["subView":iconView]))
        messageLable.translatesAutoresizingMaskIntoConstraints = false
        view.addConstraint(NSLayoutConstraint(item: messageLable, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 0.0))
        view.addConstraint(NSLayoutConstraint(item: messageLable, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 8.0))
    }

    lazy var messageLable:UILabel =
    {
        let lab = UILabel()
        lab.text = "欢迎回来"
        lab.sizeToFit()
        lab.alpha = 0
        return lab
        }()
    lazy  var iconView: UIImageView =
    {
        let iv = UIImageView(image: UIImage(named: "avatar_default_big"))
        iv.layer.masksToBounds = true
        iv.layer.cornerRadius = 45
        return iv
    }()
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
